package com.mybatis.lo;

import com.mybatis.lo.dao.UserDao;
import com.mybatis.lo.dao.UserDaoImplWithJdbc3;
import com.mybatis.lo.dao.UserDaoImplWithJdbc3LoadConfig;
import com.mybatis.lo.model.Configuration;
import com.mybatis.lo.po.User;
import org.junit.Before;
import org.junit.Test;

import java.util.List;


/**
 * V3版本的测试类
 * 在Before中加载配置
 */
public class UserDaoTestWithJdbc3 {

    Configuration configuration;

    @Before
    public void loadConfig() {
        configuration = new UserDaoImplWithJdbc3LoadConfig().loadConfig("SqlMapConfig.xml");
    }

    @Test
    public void testQueryUserById() {
        UserDao userDao = new UserDaoImplWithJdbc3(configuration);
        User user = userDao.queryUserById(1);
        System.out.println(user);
    }

    @Test
    public void testQueryUsersByUsername() {
        UserDao userDao = new UserDaoImplWithJdbc3(configuration);
        List<User> users = userDao.queryUserByName("王五");
        System.out.println(users);
    }

    @Test
    public void testQueryUsers() {
        UserDao userDao = new UserDaoImplWithJdbc3(configuration);
        User user = User.builder().username("王").build();
        List<User> users = userDao.queryUser(user);
        System.out.println(users);
    }

}
